package com.compass.doctor.ui.home.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.compass.doctor.R
import com.compass.doctor.databinding.LayoutConsumableItemBinding

import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseRecyclerViewAdapter
import com.compass.framework.model.ConsumableOrder
import com.compass.framework.model.MedicalConsumable
import com.compass.framework.model.Tag
import com.compass.framework.utils.BigDecimalUtils
import com.compass.framework.utils.getDrawableResource

/**
 * Description： 额外耗材adapter
 * Date:2024/1/15 17:32
 */
class ExtraConsumablesAdapter : BaseRecyclerViewAdapter<ConsumableOrder, LayoutConsumableItemBinding>() {
    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<LayoutConsumableItemBinding>,
        item: ConsumableOrder?,
        position: Int
    ) {
        if (item == null) return
        holder.binding.apply {
            tvName.text = getTitle(item.medicalConsumable)
            tvPayPrice.text = BigDecimalUtils.divide(item.payPrice)

        }
    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): LayoutConsumableItemBinding {
        return LayoutConsumableItemBinding.inflate(layoutInflater, parent, false)
    }

    private fun getTitle(consumables: MutableList<MedicalConsumable>): String {
        var listName = ArrayList<String?>()
        for (item in consumables) {
            listName.add("${item.name}x${item.num}")
        }
        return listName.joinToString(separator = "/")
    }
}